﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	x:Class="TeamBuildScreenSaver.Views.BuildPanel"
	x:Name="UserControl" xmlns:BuildStatus="clr-namespace:TeamBuildScreenSaver.Views" Height="144" Width="650" Background="{x:Null}">
	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="Dictionary.xaml"/>
			</ResourceDictionary.MergedDictionaries>
			<Storyboard x:Key="FadeToGreen">
				<ColorAnimation Storyboard.TargetName="FadedBackground" Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" To="#802B7720" Duration="0:0:0.5" />
			</Storyboard>
			<Storyboard x:Key="FadeToRed">
				<ColorAnimation Storyboard.TargetName="FadedBackground" Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" To="#80CF2C00" Duration="0:0:0.5" />
			</Storyboard>
			<Storyboard x:Key="FadeToGrey">
				<ColorAnimation Storyboard.TargetName="FadedBackground" Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)" To="#80717171" Duration="0:0:0.5" />
			</Storyboard>
			<Storyboard x:Key="ShowQueuedIcon">
				<DoubleAnimation To="1" Storyboard.TargetName="QueuedIcon" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="00:00:01" />
			</Storyboard>
			<Storyboard x:Key="HideQueuedIcon">
				<DoubleAnimation To="0" Storyboard.TargetName="QueuedIcon" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="00:00:01" />
			</Storyboard>
			<ControlTemplate x:Key="BuildPanelTemplate">
				<Grid x:Name="LayoutRoot">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="144"/>
						<ColumnDefinition Width="*"/>
						<ColumnDefinition Width="80"/>
					</Grid.ColumnDefinitions>
					<Grid Grid.ColumnSpan="3">
						<Rectangle x:Name="BackgroundThing" Stroke="#FF000000" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" RadiusX="16" RadiusY="16" Fill="#FFFFFFFF" HorizontalAlignment="Stretch">
							<Rectangle.RenderTransform>
								<TransformGroup>
									<ScaleTransform ScaleX="1" ScaleY="1"/>
									<SkewTransform AngleX="0" AngleY="0"/>
									<RotateTransform Angle="-180"/>
									<TranslateTransform X="0" Y="0"/>
								</TransformGroup>
							</Rectangle.RenderTransform>
							<Rectangle.BitmapEffect>
								<BitmapEffectGroup>
									<DropShadowBitmapEffect Softness="0.377953" ShadowDepth="8" Opacity="0.6" Color="#FF000000" Direction="135" Noise="0"/>
								</BitmapEffectGroup>
							</Rectangle.BitmapEffect>
						</Rectangle>
						<Rectangle x:Name="FadedBackground" Stroke="{x:Null}" StrokeThickness="1" RenderTransformOrigin="0.5,0.5" RadiusX="15" RadiusY="15" Margin="2,2,2,2">
							<Rectangle.RenderTransform>
								<TransformGroup>
									<ScaleTransform ScaleX="1" ScaleY="1"/>
									<SkewTransform AngleX="0" AngleY="0"/>
									<RotateTransform Angle="-180"/>
									<TranslateTransform X="0" Y="0"/>
								</TransformGroup>
							</Rectangle.RenderTransform>
							<Rectangle.Fill>
								<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
									<GradientStop Color="#80717171" Offset="1"/>
									<GradientStop Color="#FFFFFFFF" Offset="0"/>
								</LinearGradientBrush>
							</Rectangle.Fill>
						</Rectangle>
						<TextBlock FontSize="16" Margin="154,8,6,6" TextWrapping="Wrap" Text="{Binding Summary}" />
					</Grid>
					<Viewbox Stretch="Fill" Margin="8,8,8,8">
						<BuildStatus:BuildStatusIcon Status="{Binding Status}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="128" Width="128"/>
					</Viewbox>
					<Viewbox Grid.Column="3" Stretch="Fill" x:Name="QueuedIcon" Margin="8,8,8,8" Opacity="0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="64" Width="64">
						<ContentControl Template="{StaticResource NotStartedIcon}" />
					</Viewbox>
				</Grid>
				<ControlTemplate.Triggers>
					<DataTrigger Binding="{Binding Status}" Value="{x:Null}">
						<DataTrigger.EnterActions>
							<!--
							Frustratingly, using a StopStoryboard element within DataTrigger.ExitActions 
							occasionally does not work - so instead we need to explicitly stop 
							any storyboards that may have been started. This results in silent warnings in 
							the output window during runtime.
							 -->
							<StopStoryboard BeginStoryboardName="FailedStoryboard"/>
							<StopStoryboard BeginStoryboardName="InProgressStoryboard"/>
							<StopStoryboard BeginStoryboardName="PartiallySucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="StoppedStoryboard"/>
							<StopStoryboard BeginStoryboardName="NotStartedStoryboard"/>
              <StopStoryboard BeginStoryboardName="SucceededStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource FadeToGrey}" Name="UnknownStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
          <DataTrigger Binding="{Binding Status}" Value="Succeeded">
            <DataTrigger.EnterActions>
              <StopStoryboard BeginStoryboardName="FailedStoryboard"/>
              <StopStoryboard BeginStoryboardName="InProgressStoryboard"/>
              <StopStoryboard BeginStoryboardName="PartiallySucceededStoryboard"/>
              <StopStoryboard BeginStoryboardName="StoppedStoryboard"/>
              <StopStoryboard BeginStoryboardName="NotStartedStoryboard"/>
              <StopStoryboard BeginStoryboardName="UnknownStoryboard"/>
              <BeginStoryboard Storyboard="{StaticResource FadeToGreen}" Name="SucceededStoryboard"/>
            </DataTrigger.EnterActions>
          </DataTrigger>
					<DataTrigger Binding="{Binding Status}" Value="Failed">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="SucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="InProgressStoryboard"/>
							<StopStoryboard BeginStoryboardName="PartiallySucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="StoppedStoryboard"/>
							<StopStoryboard BeginStoryboardName="NotStartedStoryboard"/>
              <StopStoryboard BeginStoryboardName="UnknownStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource FadeToRed}" Name="FailedStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
					<DataTrigger Binding="{Binding Status}" Value="InProgress">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="SucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="FailedStoryboard"/>
							<StopStoryboard BeginStoryboardName="PartiallySucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="StoppedStoryboard"/>
							<StopStoryboard BeginStoryboardName="NotStartedStoryboard"/>
              <StopStoryboard BeginStoryboardName="UnknownStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource FadeToGrey}" Name="InProgressStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
					<DataTrigger Binding="{Binding Status}" Value="PartiallySucceeded">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="SucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="FailedStoryboard"/>
							<StopStoryboard BeginStoryboardName="InProgressStoryboard"/>
							<StopStoryboard BeginStoryboardName="StoppedStoryboard"/>
							<StopStoryboard BeginStoryboardName="NotStartedStoryboard"/>
              <StopStoryboard BeginStoryboardName="UnknownStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource FadeToRed}" Name="PartiallySucceededStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
					<DataTrigger Binding="{Binding Status}" Value="Stopped">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="SucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="FailedStoryboard"/>
							<StopStoryboard BeginStoryboardName="InProgressStoryboard"/>
							<StopStoryboard BeginStoryboardName="PartiallySucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="NotStartedStoryboard"/>
              <StopStoryboard BeginStoryboardName="UnknownStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource FadeToRed}" Name="StoppedStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
					<DataTrigger Binding="{Binding Status}" Value="NotStarted">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="SucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="FailedStoryboard"/>
							<StopStoryboard BeginStoryboardName="InProgressStoryboard"/>
							<StopStoryboard BeginStoryboardName="PartiallySucceededStoryboard"/>
							<StopStoryboard BeginStoryboardName="StoppedStoryboard"/>
              <StopStoryboard BeginStoryboardName="UnknownStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource FadeToGrey}" Name="NotStartedStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
					<DataTrigger Binding="{Binding IsQueued}" Value="True">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="HideQueuedIconStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource ShowQueuedIcon}" Name="ShowQueuedIconStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
					<DataTrigger Binding="{Binding IsQueued}" Value="False">
						<DataTrigger.EnterActions>
							<StopStoryboard BeginStoryboardName="ShowQueuedIconStoryboard"/>
							<BeginStoryboard Storyboard="{StaticResource HideQueuedIcon}" Name="HideQueuedIconStoryboard"/>
						</DataTrigger.EnterActions>
					</DataTrigger>
				</ControlTemplate.Triggers>
			</ControlTemplate>
		</ResourceDictionary>
	</UserControl.Resources>
	<ContentControl Template="{StaticResource BuildPanelTemplate}" />
</UserControl>